﻿
using System.Reflection;
using Ops.Mpc.Controllers;
namespace Ops.Mpc.Models
{
    public class VisualStateMap : IVisualStateMap
    {
        #region Fields & Properties
        public string PropertyName
        {
            get;
            set;
        }

        public string PropertyValue
        {
            get;
            set;
        }

        public string VisualState
        {
            get;
            set;
        }
        #endregion

        #region Methods
        public bool Evaluate(IController iController,Model model, string propertyName)
        {
            bool match = false;
            
            if (this.PropertyName == propertyName)
            {
                PropertyInfo propertyInfo = model.GetType().GetProperty(propertyName);

                object propertyValue = propertyInfo.GetValue(model, new object[] { });

                if (propertyValue == null && this.PropertyValue == null)
                    match = true;
                else if (propertyValue != null && this.PropertyValue != null && propertyValue.ToString().ToLower() == this.PropertyValue.ToLower())
                    match = true;

            }

            return match;
        }


        public void Execute(IController iController)
        {
            iController.Presenter.SetParentVisualState(this.VisualState);
        }

        #endregion
    }
}
